package com.tyqx.hashchainbackend.service.impl;


import com.tyqx.hashchainbackend.service.SysPermissionService;
import com.tyqx.hashchainbean.module.SysPermission;
import com.tyqx.hashchainbean.vo.PerOrResourceResultVO;
import com.tyqx.hashchainbean.vo.SysPermissionVO;
import com.tyqx.hashchaindao.mapper.SysPermissionMapper;
import hashchainutil.common.Constants;
import hashchainutil.common.EmptyUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("sysPermissionService")
public class SysPermissionServiceImpl implements SysPermissionService {

    @Resource
    SysPermissionMapper sysPermissionMapper;

    @Override
    public SysPermission getById(Long perId) throws Exception {
        return null;
    }

    @Override
    public List<PerOrResourceResultVO> getListByMap(Integer parentId) throws Exception {
        Map<String,Object> param = new HashMap<>();
        param.put("perPerentId",parentId);
        return sysPermissionMapper.getListByMap(param);
    }

    @Override
    public Integer getCountByMap(Map<String, Object> param) throws Exception {
        return null;
    }

    @Override
    public Integer save(SysPermission sysPermission) throws Exception {
        return null;
    }

    @Override
    public Integer modify(SysPermission sysPermission) throws Exception {
        return null;
    }

    @Override
    public Integer removeById(Long perId) throws Exception {
        return null;
    }

    @Override
    public List<SysPermissionVO> getListByMaps(Integer parentId) throws Exception {
        Map<String, Object> param = new HashMap<>();
        param.put("perPerentId", parentId);
        return sysPermissionMapper.getListByMaps(param);
    }

    @Override
    public List<SysPermissionVO> getSysPermissionList(Integer perId) {
        return sysPermissionMapper.getSysPermissionList(perId);
    }

    @Override
    public int pRemove(Integer perId) {
        return sysPermissionMapper.pRemove(perId);
    }

    @Override
    public int pAdd(Integer perParentId, String perName,String createBy) {
        return sysPermissionMapper.pAdd(perParentId,perName,createBy,new Date());
    }

    @Override
    public int pModify(Integer perId,String perName,String modifyBy) {
        return sysPermissionMapper.pModify(perId,perName,modifyBy,new Date());
    }

    /**
     * 根据父级ID查找下面的所有子级ID
     *
     * @param parentId
     * @return
     */
    @Override
    public List<Long> queryPerId(Long parentId) {
        return sysPermissionMapper.getPerIdByParentId(parentId);
    }

    public Integer getAllPerCou(){
        return sysPermissionMapper.getAllPerCou();
    }

    public List<SysPermissionVO> getAllPer(Integer page, Integer limit){
        page = EmptyUtils.isEmpty(page) ? Constants.DEFAULT_PAGE_NO : page;
        limit = EmptyUtils.isEmpty(limit) ? Constants.DEFAULT_PAGE_SIZE : limit;
        return sysPermissionMapper.getAllPer((page-1)* limit,limit);
    }
}
